# Pequena:   module load mvapich-intel fftw/3.2.1/intel
# Encanto:   login to service2; module load mvapich_intel cc/10.1.015

# Name of the executable
BGK     = bgk.x
VMD     = vmd.x
NLVP    = nlvp.x

#FFT_MODULE = imsl_wrap.o
#FFT_MODULE = fftw_wrap.o
FFT_MODULE = fftw3_wrap.o

MODULES =  dimensions.o parameters.o mpi_wrap.o \
           $(FFT_MODULE) fft_3d.o efield.o evolve.o advect.o

F_BGK   = set_space_vectors.o read_input.o \
          io.o  set_ic.o  diagnostics.o  collisions.o bgk.o 

F_VMD   = set_space_vectors.o  read_input.o \
          lin_io.o  lin_equil.o  lin_evolve.o  collisions.o  vmd_lin.o

F_NLVP  = set_space_vectors.o read_input.o \
          nlvp_io.o nlvp_evolve.o nlvp.o



#------------------------------------------------

# Flags and compilers

F90 = mpif90

#generic

LIB = -lfftw3
FCFLAGS = $(OPT) -c
LDFLAGS = $(OPT) $(LIB) -lm
OPT     = -i8 -r8

ifeq ($(HOSTNAME), hooloovoo)
        OPT = -fbounds-check -fdefault-real-8 -fdefault-integer-8 -O2
        LIB          = -L/usr/local/fftw/fftw-3.3.2/lib -lfftw3
        FCFLAGS      = $(OPT) -c -m64
        LDFLAGS      = $(OPT) $(LIB) -lm -m64
endif


ifeq ($(HOSTNAME), odin)
        OPT =  -fdefault-real-8 -fdefault-integer-8  -flto -Ofast
endif


ifeq ($(HOSTNAME), anterior.newmexicoconsortium.org)
        OPT = -fbounds-check -fdefault-real-8 -fdefault-integer-8 -O2
        LIB          =  -lfftw3
        FCFLAGS      = $(OPT) -c
        LDFLAGS      = $(OPT) $(LIB) -lm
endif


ifeq ($(HOSTNAME), mallorn)
        OPT = -fbounds-check -fdefault-real-8 -fdefault-integer-8
        #LIB          = -L/usr/local/fftw/fftw-2.1.5/lib -lfftw
        LIB          = -L/usr/local/fftw/fftw-3.2.2/lib -lfftw3
        FCFLAGS      = $(OPT) -c -m64 
        LDFLAGS      = $(OPT) $(LIB) -lm -m64
endif

ifeq ($(HOSTNAME), pequena)
        OPT          = -i8 -r8
        LIB          = -lfftw3
        FCFLAGS      = $(OPT) -c
        LDFLAGS      = $(OPT) $(LIB) -lm
endif

ifeq ($(HOSTNAME), service2)
        OPT         = -i8 -r8
        FFTW_HOME   =  /apps/fftw/lib/fftw-2.1.5
        FCFLAGS     = $(OPT)  -I$(FFTW_HOME)/include  -c
        LDFLAGS     = $(OPT)  -I$(FFTW_HOME)/lib  -lfftw_mpi -lfftw -c
endif




# -------------------------------------------------------
# compile

# $(BGK): $(MODULES) 

%.o: %.f
	$(F90) $(FCFLAGS) $<

%.o: %.f90
	$(F90) $(FCFLAGS) $<


default:
	@echo "\n   options:   bgk, vmd, nlvp, hostname\n"

bgk:  $(MODULES) $(F_BGK)
	$(F90) $(MODULES) $(F_BGK) -o $(BGK) $(LDFLAGS)

vmd:  $(MODULES) $(F_VMD)
	$(F90) $(MODULES) $(F_VMD) -o $(VMD) $(LDFLAGS)

nlvp: $(MODULES) $(F_NLVP)
	$(F90) $(MODULES) $(F_NLVP) -o $(NLVP) $(LDFLAGS)


hostname:
	@echo $(HOSTNAME)

clean:
	rm -f *~ *.o *.mod
